package com.demo.sso.sdk.config;

import org.springframework.boot.context.properties.ConfigurationProperties;

/**
 * SSO SDK配置属性类
 * 
 * @author SpringCloud团队
 * @version 1.0.0
 * @since 2025-01-01
 */
@ConfigurationProperties(prefix = "sso.sdk")
public class SsoSdkProperties {

    /**
     * SSO服务器地址（必填）
     * 例如：http://sso.example.com
     */
    private String serverUrl;

    /**
     * 客户端ID（必填）
     * 由SSO管理员分配的唯一标识
     */
    private String clientId;

    /**
     * 客户端密钥（必填）
     * 由SSO管理员分配的密钥
     */
    private String clientSecret;

    /**
     * 回调地址（必填）
     * 用户登录成功后的回调地址
     */
    private String redirectUri;

    /**
     * 登录页面路径（可选）
     * 默认：/login
     */
    private String loginPath = "/login";

    /**
     * 登出页面路径（可选）
     * 默认：/logout
     */
    private String logoutPath = "/logout";

    /**
     * 回调处理路径（可选）
     * 默认：/sso/callback
     */
    private String callbackPath = "/sso/callback";

    /**
     * 会话过期时间（秒）（可选）
     * 默认：3600秒（1小时）
     */
    private Integer sessionTimeout = 3600;

    /**
     * 是否启用SSO（可选）
     * 默认：true
     */
    private Boolean enabled = true;

    /**
     * HTTP连接超时时间（毫秒）（可选）
     * 默认：5000毫秒
     */
    private Integer connectTimeout = 5000;

    /**
     * HTTP读取超时时间（毫秒）（可选）
     * 默认：10000毫秒
     */
    private Integer readTimeout = 10000;

    /**
     * 忽略SSL证书验证（可选）
     * 默认：false
     */
    private Boolean ignoreSsl = false;

    /**
     * 用户信息缓存时间（秒）（可选）
     * 默认：300秒（5分钟）
     */
    private Integer userInfoCacheTimeout = 300;

    // Getters and Setters

    public String getServerUrl() {
        return serverUrl;
    }

    public void setServerUrl(String serverUrl) {
        this.serverUrl = serverUrl;
    }

    public String getClientId() {
        return clientId;
    }

    public void setClientId(String clientId) {
        this.clientId = clientId;
    }

    public String getClientSecret() {
        return clientSecret;
    }

    public void setClientSecret(String clientSecret) {
        this.clientSecret = clientSecret;
    }

    public String getRedirectUri() {
        return redirectUri;
    }

    public void setRedirectUri(String redirectUri) {
        this.redirectUri = redirectUri;
    }

    public String getLoginPath() {
        return loginPath;
    }

    public void setLoginPath(String loginPath) {
        this.loginPath = loginPath;
    }

    public String getLogoutPath() {
        return logoutPath;
    }

    public void setLogoutPath(String logoutPath) {
        this.logoutPath = logoutPath;
    }

    public String getCallbackPath() {
        return callbackPath;
    }

    public void setCallbackPath(String callbackPath) {
        this.callbackPath = callbackPath;
    }

    public Integer getSessionTimeout() {
        return sessionTimeout;
    }

    public void setSessionTimeout(Integer sessionTimeout) {
        this.sessionTimeout = sessionTimeout;
    }

    public Boolean getEnabled() {
        return enabled;
    }

    public void setEnabled(Boolean enabled) {
        this.enabled = enabled;
    }

    public Integer getConnectTimeout() {
        return connectTimeout;
    }

    public void setConnectTimeout(Integer connectTimeout) {
        this.connectTimeout = connectTimeout;
    }

    public Integer getReadTimeout() {
        return readTimeout;
    }

    public void setReadTimeout(Integer readTimeout) {
        this.readTimeout = readTimeout;
    }

    public Boolean getIgnoreSsl() {
        return ignoreSsl;
    }

    public void setIgnoreSsl(Boolean ignoreSsl) {
        this.ignoreSsl = ignoreSsl;
    }

    public Integer getUserInfoCacheTimeout() {
        return userInfoCacheTimeout;
    }

    public void setUserInfoCacheTimeout(Integer userInfoCacheTimeout) {
        this.userInfoCacheTimeout = userInfoCacheTimeout;
    }

    /**
     * 验证配置是否有效
     */
    public boolean isValid() {
        return serverUrl != null && !serverUrl.trim().isEmpty()
                && clientId != null && !clientId.trim().isEmpty()
                && clientSecret != null && !clientSecret.trim().isEmpty()
                && redirectUri != null && !redirectUri.trim().isEmpty();
    }

    @Override
    public String toString() {
        return "SsoSdkProperties{" +
                "serverUrl='" + serverUrl + '\'' +
                ", clientId='" + clientId + '\'' +
                ", clientSecret='***'" +
                ", redirectUri='" + redirectUri + '\'' +
                ", loginPath='" + loginPath + '\'' +
                ", logoutPath='" + logoutPath + '\'' +
                ", callbackPath='" + callbackPath + '\'' +
                ", sessionTimeout=" + sessionTimeout +
                ", enabled=" + enabled +
                ", connectTimeout=" + connectTimeout +
                ", readTimeout=" + readTimeout +
                ", ignoreSsl=" + ignoreSsl +
                ", userInfoCacheTimeout=" + userInfoCacheTimeout +
                '}';
    }
}